class Utils {


  /**
   * 强制转换为数组
   * @param arrayLike
   */
  static castArray<T>(arrayLike: T | T[]): T[] {
    if (Array.isArray(arrayLike)) return arrayLike
    return [arrayLike]
  }


  static isUndefined(obj: any) {
    return Object.is(obj, undefined)
  }

  static isNull(obj: any) {
    return Object.is(obj, null)
  }

  static isNil(obj: any) {
    return Utils.isUndefined(obj) || Utils.isNull(obj)
  }

  static noop() {
    return undefined
  }

  static assign(source: Record<string, any>, object: Record<string, any>) {
    return Object.assign({}, source, object)
  }

  static defaultTo(value: any, defaultValue: any) {
    return Utils.isNil(value) ? defaultValue : value
  }

  static ceil(number: number) {
    return Math.ceil(number)
  }

  static eq(value: any, otherValue: any) {
    return value === otherValue
  }

  static prefixName(prefix: string): string {
    return `${prefix}_` + Utils.ceil(Math.random() * 10000)
  }

  static isBoolean(value: any): boolean {
    return typeof value === 'boolean'
  }

  static isObject(value: any) {
    return typeof value === 'object' && value !== null
  }

  static isArray(arrayLike: any): boolean {
    return Array.isArray(arrayLike)
  }

  static isEmpty(object: [] | Record<string, any>) {
    if (Utils.isObject(object)) {
      return Object.keys(object).length === 0
    }

    if (Utils.isArray(object)) {
      return object.length === 0
    }

  }

}

export default Utils
